package com.shg.web.action.bbs;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.shg.bean.PageView;
import com.shg.bean.QueryResult;
import com.shg.bean.bbs.Forum;
import com.shg.service.bbs.ForumService;
import com.shg.web.tools.WebTool;

@Controller
public class ForumAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//分页工具
	private PageView<Forum> pageView;
	//每页显示的最大纪录数
	private Integer maxrecord=15;
	//当前页
	private Integer currentpage=1;
	//书籍的ID
	private String bookid;
	//
	private Forum forum;
	//
	private  String message;
	
	@Resource ForumService forumService;
	/**
	 * 书籍讨论专区 
	 */
	public String discuss(){
		pageView = new PageView<Forum>(maxrecord, currentpage);
		QueryResult<Forum> queryResult;
		try {
			queryResult = forumService.getDiscuss(
								pageView.getFirstResult(), pageView.getMaxrecord(), bookid,0);
		} catch (Exception e) {
			e.printStackTrace();
			this.message="操作发生异常";
			return "error";
		}
		pageView.setQueryResult(queryResult);
		return "discuss";
	}
	/**
	 * 发表评论
	 * @return 
	 */
	public String publish(){
		forum.setUsers(WebTool.getLogin());
		forumService.insert(forum);
		discuss();
		 return "publish";
	}
	public PageView<Forum> getPageView() {
		return pageView;
	}
	public void setPageView(PageView<Forum> pageView) {
		this.pageView = pageView;
	}
	public Integer getMaxrecord() {
		return maxrecord;
	}
	public void setMaxrecord(Integer maxrecord) {
		this.maxrecord = maxrecord;
	}
	public Integer getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(Integer currentpage) {
		this.currentpage = currentpage;
	}
	public String getBookid() {
		return bookid;
	}
	public void setBookid(String bookid) {
		this.bookid = bookid;
	}
	public Forum getForum() {
		return forum;
	}
	public void setForum(Forum forum) {
		this.forum = forum;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

}
